//
//  NSMutableAttributedString+ATKit.m
//  FDLive
//
//  Created by CoderLT on 2017/8/7.
//  Copyright © 2017年 FDLive. All rights reserved.
//

#import "NSMutableAttributedString+ATKit.h"

@implementation NSAttributedString (ATKit)
+ (instancetype)attractment:(UIImage *)image {
    return [self attractment:image bounds:CGRectZero];
}
+ (instancetype)attractment:(UIImage *)image bounds:(CGRect)bounds {
    NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
    attachment.image = image;
    attachment.bounds = CGRectIsEmpty(bounds) ? CGRectMake(0, 0, image.size.width, image.size.height) : bounds;
    return [NSAttributedString attributedStringWithAttachment:attachment];
}
@end

@implementation NSMutableAttributedString (ATKit)
- (void)appendIcon:(UIImage *)image {
    return [self appendIcon:image bounds:CGRectZero];
}
- (void)appendIcon:(UIImage *)image bounds:(CGRect)bounds {
    return [self appendAttributedString:[NSAttributedString attractment:image bounds:bounds]];
}
- (void)appendString:(NSString *)string attribute:(nullable NSDictionary<NSString *, id> *)attribute {
    if (!string.length) {
        return;
    }
    return [self appendAttributedString:[[NSAttributedString alloc] initWithString:string attributes:attribute]];
}
@end
